/**
 created by xwy 2018/3/17 15:25
 user: 13720092498@163.com
 **/

import React, { Component } from 'react'
import { Button } from 'antd';
import {increment, decrement, reset} from '../../redux/actions/counter'
import {connect} from 'react-redux'
import {getUser} from "../../api/api";
import './Index.less'
class Tpl extends Component {
    state = {visible: false, info: []}
    showModal = () => {
      this.props.history.push('/test')
    }
     getUser = () => {
       getUser().then(res => {
         this.setState({
           info: res.data
         })
       })
     }
  getEmpty = () => {
    this.setState({
      info: []
    })
  }
    render () {
      return (
      <div>
        <h1>redux测试</h1>
        <h3>当前计数为{this.props.counter.count}</h3>
        <Button type="danger" onClick={() => this.props.increment()}>增加</Button>
        <Button type="default" onClick={() => this.props.decrement()}>减少</Button>
        <Button type="dashed" onClick={() => this.props.reset()}>reset</Button>

        <br/>
        <h1>跳转路由测试</h1>
        <Button onClick={this.showModal} type="primary">Primary</Button>
        <h1>接口测试</h1>
        <Button onClick={this.getUser} type="primary">掉接口</Button>
        <Button onClick={this.getEmpty} type="primary">清空数据</Button>
        <h3>返回数据</h3>
        <div>{JSON.stringify(this.state.info)}</div>
      </div>
      )
    }
}

const mapStateToProps = (state) => {
  return {
    counter: state.counter
  }
}

const mapDisPatchToProps = (dispatch) => {
  return {
    increment: () => {
      dispatch(increment())
    },
    decrement: () => {
      dispatch(decrement())
    },
    reset: () => {
      dispatch(reset())
    }
  }
}
export default connect(mapStateToProps, mapDisPatchToProps)(Tpl);
